@echo off
echo "==>TAO_ROOT=%TAO_ROOT%"
set PROJECT_PATH="%TAO_ROOT%/orbsvcs/tests/FT_Naming/FaultTolerant"
cd %PROJECT_PATH%


::1) Create empty NameService and GroupService directories
rmdir /s /q NameService
rmdir /s /q GroupService
timeout /t 3
mkdir NameService
mkdir GroupService
timeout /t 3

@echo off
setlocal

:: 定义要删除的文件列表
set "files=*.ior"

:: 遍历文件列表并删除存在的文件
for %%f in (%files%) do (
    if exist "%%f" (
        echo Deleting %%f...
        del "%%f"
        if not errorlevel 1 (
            echo Deleted %%f successfully.
        ) else (
            echo Error deleting %%f.
        )
    ) else (
        echo %%f does not exist. Skipping.
    )
)


timeout /t 3
:: PRIMARY 设置ip 和端口 
set "PRIMARY_IP_PORT=OMEN_2023:23261" 
::BACKUP 设置ip 和端口 
set "BACKUP_IP_PORT=OMEN_2023:38586" 

REM 打开新终端并执行命令  -m 0 不使用多播 -r 持久化文件目录 -v 对象组持久化文件目录
echo "==>start primary tao_ft_naming iiop://%PRIMARY_IP_PORT%"
start "primary_tao_ft_naming" cmd /k "%TAO_ROOT%/orbsvcs/FT_Naming_Service/tao_ft_naming --primary -ORBListenEndPoints iiop://%PRIMARY_IP_PORT% -m 0 -r NameService -v GroupService"
timeout /t 10

@REM -c 输出对象标识  -g 命名管理器的多配置文件 IOR
echo "==>Start backup tao_ft_naming  iiop://%BACKUP_IP_PORT%"
start "backup_tao_ft_naming" cmd /k "%TAO_ROOT%/orbsvcs/FT_Naming_Service/tao_ft_naming --backup -ORBDebugLevel 0 -ORBListenEndPoints iiop://%BACKUP_IP_PORT% -c %PROJECT_PATH%/ns.ior -g %PROJECT_PATH%/nm.ior -m 0 -r NameService -v GroupService"


echo "==>Manually close the terminal tao_ft_naming!!!!"

set /p user_choice=please input(hand kill primary,and 1 to start the client):

@REM 手动杀死主命名服务后，测试客户端是否能够无缝连接到备用服务器。
if "%user_choice%"=="1" (
	echo  "==>Start client"
	start "client" cmd /k "client --failover -ORBDebugLevel 0 -p file://%PROJECT_PATH%/ns.ior -r file://%PROJECT_PATH%/nm.ior -b 4 -d 4"
)


@REM //////////////////////////////////////////////////////////////////////////////
@REM 	// optional
@REM 	//////////////////////////////////////////////////////////////////////////////
@REM 	// -b <breadth of context tree>
@REM 	// -d <depth of context tree>
@REM 	// -o <breadth of object tree>
@REM 	//////////////////////////////////////////////////////////////////////////////
@REM 	// required
@REM 	//////////////////////////////////////////////////////////////////////////////
@REM 	// -p <ior of first name server>
@REM 	// -q <ior of second name server>
@REM 	// -r <ior of first naming service>
@REM 	// -s <ior of second naming service>
@REM 	// --failover run fault tolerant failover test
@REM 	// --persistence run fault tolerant persistence test
@REM 	// --equivalence run fault tolerant equivalence test
@REM 	//////////////////////////////////////////////////////////////////////////////
@REM 	// required with persistance
@REM 	//////////////////////////////////////////////////////////////////////////////
@REM 	// --create run creation test phase
@REM 	// --validate run validation test phase


@REM ===================================
@REM ::创建对象组
@REM %ACE_ROOT%/bin/tao_nsgroup group_create -group ieee -policy round -ORBInitRef NameService=file://ns.ior -ORBInitRef NamingManager=file://nm.ior

@REM ::移除对象组 若绑定了,先解绑
@REM %ACE_ROOT%/bin/tao_nsgroup group_remove -group ieee -ORBInitRef NameService=file://ns.ior -ORBInitRefNamingManager=file://nm.ior

@REM ::绑定对象组
@REM %ACE_ROOT%/bin/tao_nsgroup group_bind -group ieee -name iso/ieee -ORBInitRef NameService=file://ns.ior -ORBInitRef NamingManager=file://nm.ior

@REM ::解绑对象组
@REM %ACE_ROOT%/bin/tao_nsgroup group_unbind -name iso/ieee -ORBInitRef NameService=file://ns.ior -ORBInitRef NamingManager=file://nm.ior

@REM ::列举对象组
@REM %ACE_ROOT%/bin/tao_nsgroup group_list -ORBInitRef NameService=file://ns.ior -ORBInitRef NamingManager=file://nm.ior

@REM ::向对象组添加成员
@REM %ACE_ROOT%/bin/tao_nsgroup member_add -group ieee -location local -ior file://mo.ior -ORBInitRef NameService=file://ns.ior -ORBInitRef NamingManager=file://nm.ior

@REM ::向对象组删除成员
@REM %ACE_ROOT%/bin/tao_nsgroup member_remove -group ieee -location local -ORBInitRef NameService=file://ns.ior -ORBInitRef NamingManager=file://nm.ior

@REM ::列举对象组成员
@REM %ACE_ROOT%/bin/tao_nsgroup member_list -group ieee -ORBInitRef NameService=file://ns.ior -ORBInitRef NamingManager=file://nm.ior

@REM ::展示对象组成员引用信息
@REM %ACE_ROOT%/bin/tao_nsgroup member_show -group ieee -location local -ORBInitRef NameService=file://ns.ior -ORBInitRef NamingManager=file://nm.ior